// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Fluent;
using Elastic.Clients.Elasticsearch.Requests;
using Elastic.Clients.Elasticsearch.Serialization;
using Elastic.Transport;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.IndexLifecycleManagement;

public sealed partial class PutLifecycleRequestParameters : RequestParameters
{
	/// <summary>
	/// <para>Period to wait for a connection to the master node. If no response is received before the timeout expires, the request fails and returns an error.</para>
	/// </summary>
	public Elastic.Clients.Elasticsearch.Duration? MasterTimeout { get => Q<Elastic.Clients.Elasticsearch.Duration?>("master_timeout"); set => Q("master_timeout", value); }

	/// <summary>
	/// <para>Period to wait for a response. If no response is received before the timeout expires, the request fails and returns an error.</para>
	/// </summary>
	public Elastic.Clients.Elasticsearch.Duration? Timeout { get => Q<Elastic.Clients.Elasticsearch.Duration?>("timeout"); set => Q("timeout", value); }
}

/// <summary>
/// <para>Creates a lifecycle policy. If the specified policy exists, the policy is replaced and the policy version is incremented.</para>
/// </summary>
public sealed partial class PutLifecycleRequest : PlainRequest<PutLifecycleRequestParameters>
{
	public PutLifecycleRequest(Elastic.Clients.Elasticsearch.Name name) : base(r => r.Required("policy", name))
	{
	}

	internal override ApiUrls ApiUrls => ApiUrlLookup.IndexLifecycleManagementPutLifecycle;

	protected override HttpMethod StaticHttpMethod => HttpMethod.PUT;

	internal override bool SupportsBody => true;

	internal override string OperationName => "ilm.put_lifecycle";

	/// <summary>
	/// <para>Period to wait for a connection to the master node. If no response is received before the timeout expires, the request fails and returns an error.</para>
	/// </summary>
	[JsonIgnore]
	public Elastic.Clients.Elasticsearch.Duration? MasterTimeout { get => Q<Elastic.Clients.Elasticsearch.Duration?>("master_timeout"); set => Q("master_timeout", value); }

	/// <summary>
	/// <para>Period to wait for a response. If no response is received before the timeout expires, the request fails and returns an error.</para>
	/// </summary>
	[JsonIgnore]
	public Elastic.Clients.Elasticsearch.Duration? Timeout { get => Q<Elastic.Clients.Elasticsearch.Duration?>("timeout"); set => Q("timeout", value); }
	[JsonInclude, JsonPropertyName("policy")]
	public Elastic.Clients.Elasticsearch.IndexLifecycleManagement.IlmPolicy? Policy { get; set; }
}

/// <summary>
/// <para>Creates a lifecycle policy. If the specified policy exists, the policy is replaced and the policy version is incremented.</para>
/// </summary>
public sealed partial class PutLifecycleRequestDescriptor : RequestDescriptor<PutLifecycleRequestDescriptor, PutLifecycleRequestParameters>
{
	internal PutLifecycleRequestDescriptor(Action<PutLifecycleRequestDescriptor> configure) => configure.Invoke(this);

	public PutLifecycleRequestDescriptor(Elastic.Clients.Elasticsearch.Name name) : base(r => r.Required("policy", name))
	{
	}

	internal override ApiUrls ApiUrls => ApiUrlLookup.IndexLifecycleManagementPutLifecycle;

	protected override HttpMethod StaticHttpMethod => HttpMethod.PUT;

	internal override bool SupportsBody => true;

	internal override string OperationName => "ilm.put_lifecycle";

	public PutLifecycleRequestDescriptor MasterTimeout(Elastic.Clients.Elasticsearch.Duration? masterTimeout) => Qs("master_timeout", masterTimeout);
	public PutLifecycleRequestDescriptor Timeout(Elastic.Clients.Elasticsearch.Duration? timeout) => Qs("timeout", timeout);

	public PutLifecycleRequestDescriptor Name(Elastic.Clients.Elasticsearch.Name name)
	{
		RouteValues.Required("policy", name);
		return Self;
	}

	private Elastic.Clients.Elasticsearch.IndexLifecycleManagement.IlmPolicy? PolicyValue { get; set; }
	private Elastic.Clients.Elasticsearch.IndexLifecycleManagement.IlmPolicyDescriptor PolicyDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.IndexLifecycleManagement.IlmPolicyDescriptor> PolicyDescriptorAction { get; set; }

	public PutLifecycleRequestDescriptor Policy(Elastic.Clients.Elasticsearch.IndexLifecycleManagement.IlmPolicy? policy)
	{
		PolicyDescriptor = null;
		PolicyDescriptorAction = null;
		PolicyValue = policy;
		return Self;
	}

	public PutLifecycleRequestDescriptor Policy(Elastic.Clients.Elasticsearch.IndexLifecycleManagement.IlmPolicyDescriptor descriptor)
	{
		PolicyValue = null;
		PolicyDescriptorAction = null;
		PolicyDescriptor = descriptor;
		return Self;
	}

	public PutLifecycleRequestDescriptor Policy(Action<Elastic.Clients.Elasticsearch.IndexLifecycleManagement.IlmPolicyDescriptor> configure)
	{
		PolicyValue = null;
		PolicyDescriptor = null;
		PolicyDescriptorAction = configure;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (PolicyDescriptor is not null)
		{
			writer.WritePropertyName("policy");
			JsonSerializer.Serialize(writer, PolicyDescriptor, options);
		}
		else if (PolicyDescriptorAction is not null)
		{
			writer.WritePropertyName("policy");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.IndexLifecycleManagement.IlmPolicyDescriptor(PolicyDescriptorAction), options);
		}
		else if (PolicyValue is not null)
		{
			writer.WritePropertyName("policy");
			JsonSerializer.Serialize(writer, PolicyValue, options);
		}

		writer.WriteEndObject();
	}
}